package com.foreknow.dao.inpl;

import com.foreknow.dao.HelloDao;
import com.foreknow.mapping.EntityMapping;
import com.foreknow.model.Hello;

import java.sql.SQLException;
import java.util.List;

public class HelloDaoImpl extends BaseDao implements HelloDao {


    /**
     * 查询所有
     * @param
     * @return
     */
    @Override
    public List<Object> add() {
        String sql="select * from hello";
        EntityMapping mapping= mappingFactory.getMap("HELLO_MAPPINGIMPL");
       List<Object> list=jdbcTemplate.query(sql,mapping);
        return list;
    }

    @Override
    public Hello query(int id) {
        String sql = "select * from hello where id=?";
        EntityMapping mapping= mappingFactory.getMap("HELLO_MAPPINGIMPL");
        List<Object>list=jdbcTemplate.query(sql,mapping,id);
        if (list.size()>0){
            return (Hello) list.get(0);
        }else {
            return null;

        }
    }

    @Override
    public boolean update (Hello hello) throws SQLException {
        String sql="update hello set name=?,age=? where id=?";
        int update =jdbcTemplate.update(sql,hello.getName(),hello.getAge(),hello.getId());
        return update==1;
    }
}
